clear all

* Set working directory: this should work if you save the replication folder on your desktop, but please change as needed
cd "~/Desktop/vw_negativity_replication/"

set matsize 10000

** 
** CORRELATIONS BETWEEN EMOTIONS IN EACH SPEECH **

use data_raw, clear

correl angernorm fearnorm disgustnorm sadnessnorm joynorm ///
enthusiasmnorm pridenorm hopenorm

**********************************************************
** ANALYSES WITH MONTHLY DATA, CENTERED AROUND ELECTION **
**********************************************************

* Opening the dataset

use thirdtry_collapsed_monthly, clear

* Setting up data for fixed effects

xtset actor_code month 

* Analysing

local outcomes angernorm fearnorm disgustnorm sadnessnorm joynorm ///
enthusiasmnorm pridenorm hopenorm pos_sentiments_pca neg_sentiments_pca

* A fake model just to create a dataset with findings	
	
regr state_code afd if main_party == 1, cluster(actor_code)
regsave afd using findings.dta, ci level(95) replace pval ///
addlabel (Outcome, fake, Sample, "Without AfD", Period, "Monthly", Model, "Descriptives", ///
Specification, "SE's clustered by actor")

** Keeping only the main parties

keep if party_code == 1 | ///
party_code == 2 | ///
party_code == 3 | ///
party_code == 4 | ///
party_code == 7 | ///
party_code == 8 | ///
party_code == 11


* Main analyses with unstandardized outcomes
eststo clear

foreach outcome in `outcomes'{

xtreg `outcome' after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
estimates store `outcome'
}

* Make table with unstandardized coefficients
esttab angernorm fearnorm disgustnorm sadnessnorm neg_sentiments_pca joynorm ///
enthusiasmnorm pridenorm hopenorm pos_sentiments_pca  ///
using main_unstandardized.tex, tex nostar se replace ///
mtitles("Anger" "Fear" "Disgust" "Sadness" "Neg emotions (PCA)" ///
"Joy" "Enthusiasm" "Pride" "Hope" "Pos emotions (PCA)") keep(after_state_elec _cons)coeflabels (after_state_elec "After state election"  _cons "Constant") addnotes("All models include actor and month-to-election fixed effects." "Standard errors are clustered by actor.")


* Make a table with the summary statistics each outcome variable in the control group, for comparison sake
* First label the variables
label variable angernorm Anger
label variable fearnorm Fear
label variable disgustnorm Disgust
label variable sadnessnorm Sadness
label variable joynorm Joy
label variable enthusiasmnorm Enthusiasm
label variable pridenorm Pride
label variable hopenorm Hope

sutex2 angernorm fearnorm disgustnorm sadnessnorm joynorm enthusiasmnorm pridenorm hopenorm  if after_state_elec == 0 & afd == 0 & main_party == 1, replace digits(6) ///
saving(summary_stats.tex) minmax tabular varlabels

foreach outcome in `outcomes'{
* Main analyses with standardized outcomes
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Main analyses with logged outcomes
xtreg `outcome'_stnd_log after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Logged outcomes") 

* Main analyses with logged outcomes
xtreg `outcome'_stnd_log after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Logged outcomes") 

** HETEROGENEOUS TREATMENT EFFECTS BASED ON LEVEL OF EMOTIONALITY BY AFD
* States where AfD is more emotional than mean
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ///
mean_neg_emotions_afd > overall_mean_neg_emotions_afd, fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "States with rad right neg emotionality above median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* States where AfD is less emotional than mean
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ///
mean_neg_emotions_afd < overall_mean_neg_emotions_afd, fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "States with rad right neg emotionality below median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** HETEROGENEOUS TREATMENT EFFECTS BASED ON PARTY OF THE MP
* Right-wing parties
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & right == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Right-wing MPs (excluding AfD)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Left-wing parties
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & left == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Left-wing MPs", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Left-wing parties (excluding Die Linke)
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & left == 1 & party_code != 8, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Left-wing MPs (excluding The Left)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Party by party
* CDU + CSU
xtreg `outcome'_stnd after_state_elec i.month if party_code == 2 | party_code == 3, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from CDU + CSU", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* FDP
xtreg `outcome'_stnd after_state_elec i.month if party_code == 4, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from FDP", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Greens
xtreg `outcome'_stnd after_state_elec i.month if party_code == 7, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from Greens", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Die Linke
xtreg `outcome'_stnd after_state_elec i.month if party_code == 8, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from Die Linke", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 
 
* SPD
xtreg `outcome'_stnd after_state_elec i.month if party_code == 11, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from SPD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** ANALYSES EXCLUDING DIE LINKE
xtreg `outcome'_stnd after_state_elec i.month if party_code != 1 & party_code != 8, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from mainstream parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

** ANALYSES EXCLUDING DIE LINKE AND GREENS
xtreg `outcome'_stnd after_state_elec i.month if party_code != 1 & party_code != 8 & party_code != 7, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from mainstream parties (excluding Greens)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

** Analyses using only incumbents
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & incumbent == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Incumbents", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** Analyses conditional on how much AfD discusses in parliament
 
* where radical right makes the most speeches
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & speeches_per_month_afd > median_speeches_per_month_afd, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Rad right speech frequency above median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

* where radical right makes the least speeches
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & speeches_per_month_afd < median_speeches_per_month_afd, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Rad right speech frequency below median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 


** Analyses conditional on how much rad right discusses them

* Issues the radical right discusses the most
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & typical_radright == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues rad right MPs discuss the most", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

* Issues the radical right discusses the least
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & typical_radright == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues rad right MPs discuss the least", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Issues with salience difference above median
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & salience_diff > median_salience_diff, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues with salience difference above median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Issues with salience difference below median
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & salience_diff < median_salience_diff, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues with salience difference below median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** Analyses only for topics related to migration versus others
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & (topic_7 == 1 | topic_21 == 1), ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Topics related to migration", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & topic_7 != 1 & topic_21 != 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Topics not related to migration", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** Analyses by government and opposition 
* Analyses for parties in government before the election took place
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_before == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from previous gov parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the government formed after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_after == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from subsequent gov parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the government before and after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_both == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from re-elected gov parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in opposition before the election took place
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_before == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from previous opposition parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the opposition after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_after == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from subsequent opposition parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the opposition before and after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_after == 0 & ingov_before == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from re-elected opposition parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses with year fixed effects as well
xtreg `outcome'_stnd after_state_elec i.month i.year if afd == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Month and year fixed effects") 

* Analyses with state fixed effects instead
reg `outcome'_stnd after_state_elec i.month i.state_code if afd == 0 & main_party == 1, cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "State fixed effects") 

** Jackknives (removing one state at a time)
forvalues x = 1/16{
	xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 ///
	& state_code != `x', fe cluster(actor_code)
	regsave after_state_elec using findings.dta, ci level(95) append pval ///
	addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Jackknives", ///
	Specification, "Year fixed effects", State, `x') 
	}
}	


************************************************
** SAME THING WITH 90% CI'S, SO WE CAN APPEND **
************************************************


local outcomes angernorm fearnorm disgustnorm ///
sadnessnorm joynorm enthusiasmnorm pridenorm hopenorm ///
pos_sentiments_pca neg_sentiments_pca 

* A fake model just to create a dataset with findings	
	
regr state_code afd if main_party == 1, cluster(actor_code)
regsave afd using findings_90.dta, ci level(90) replace pval ///
addlabel (Outcome, fake, Sample, "Without AfD", Period, "Monthly", Model, "Descriptives", ///
Specification, "SE's clustered by actor")

foreach outcome in `outcomes'{

* Main analyses
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Main analyses with logged outcomes
xtreg `outcome'_stnd_log after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Logged outcomes") 

** HETEROGENEOUS TREATMENT EFFECTS BASED ON LEVEL OF EMOTIONALITY BY AFD
* States where AfD is more emotional than mean
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ///
mean_neg_emotions_afd > overall_mean_neg_emotions_afd, fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "States with rad right neg emotionality above median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* States where AfD is less emotional than mean
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ///
mean_neg_emotions_afd < overall_mean_neg_emotions_afd, fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "States with rad right neg emotionality below median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** HETEROGENEOUS TREATMENT EFFECTS BASED ON PARTY OF THE MP
* Right-wing parties
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & right == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Right-wing MPs (excluding AfD)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Left-wing parties
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & left == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Left-wing MPs", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Left-wing parties (excluding Die Linke)
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & left == 1 & party_code != 8, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Left-wing MPs (excluding The Left)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Party by party
* CDU + CSU
xtreg `outcome'_stnd after_state_elec i.month if party_code == 2 | party_code == 3, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from CDU + CSU", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* FDP
xtreg `outcome'_stnd after_state_elec i.month if party_code == 4, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from FDP", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Greens
xtreg `outcome'_stnd after_state_elec i.month if party_code == 7, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from Greens", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Die Linke
xtreg `outcome'_stnd after_state_elec i.month if party_code == 8, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from Die Linke", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 
 
* SPD
xtreg `outcome'_stnd after_state_elec i.month if party_code == 11, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from SPD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** ANALYSES EXCLUDING DIE LINKE
xtreg `outcome'_stnd after_state_elec i.month if party_code != 1 & party_code != 8, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from mainstream parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

** ANALYSES EXCLUDING DIE LINKE AND GREENS
xtreg `outcome'_stnd after_state_elec i.month if party_code != 1 & party_code != 8 & party_code != 7, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from mainstream parties (excluding Greens)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

** Analyses using only incumbents
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & incumbent == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Incumbents", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** Analyses conditional on how much AfD discusses in parliament
 
* where radical right makes the most speeches
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & speeches_per_month_afd > median_speeches_per_month_afd, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Rad right speech frequency above average", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

* where radical right makes the least speeches
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & speeches_per_month_afd < median_speeches_per_month_afd, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Rad right speech frequency below average", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** Analyses conditional on how much rad right discusses them

* Issues the radical right discusses the most
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & typical_radright == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues rad right MPs discuss the most", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects")

* Issues the radical right discusses the least
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & typical_radright == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues rad right MPs discuss the least", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Issues with salience difference above median
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & salience_diff > median_salience_diff, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues with salience difference above median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Issues with salience difference below median
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & salience_diff < median_salience_diff, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues with salience difference below median", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Issues whose level of salience decreased
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & increasing_salience == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Issues whose salience decreased", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** Analyses only for topics related to migration versus others
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & (topic_7 == 1 | topic_21 == 1), ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Topics related to migration", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & topic_7 != 1 & topic_21 != 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Topics not related to migration", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

** Analyses by government and opposition 
* Analyses for parties in government before the election took place
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_before == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from previous gov parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the government formed after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_after == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from subsequent gov parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the government before and after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_both == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from re-elected gov parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in opposition before the election took place
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_before == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from previous opposition parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the opposition after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_after == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from subsequent opposition parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses for parties in the opposition before and after the election
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 & ingov_after == 0 & ingov_before == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "MPs from re-elected opposition parties", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses with year fixed effects as well
xtreg `outcome'_stnd after_state_elec i.month i.year if afd == 0, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Month and year fixed effects") 

** Analyses with state fixed effects instead
reg `outcome'_stnd after_state_elec i.month i.state_code if afd == 0 & main_party == 1, cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "State fixed effects") 

** Jackknives (removing one state at a time)
forvalues x = 1/16{
	xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1 ///
	& state_code != `x', fe cluster(actor_code)
	regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
	addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "Monthly", Model, "Jackknives", ///
	Specification, "Year fixed effects", State, `x') 
	}

}



** Analyses with all parties (without removing small ones)

* Opening the dataset

use thirdtry_collapsed_monthly, clear

* Setting up data for fixed effects

xtset actor_code month 

* Analysing

local outcomes angernorm fearnorm disgustnorm sadnessnorm joynorm ///
enthusiasmnorm pridenorm hopenorm pos_sentiments_pca neg_sentiments_pca

foreach outcome in `outcomes'{
* With 95% CI
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "All parties (including small ones)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* With 90% CI
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "All parties (including small ones)", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 
}

** Analyses without collapsing by month-to-election
* Opening the dataset
use thirdtry_collapsed_bydate, clear

* Setting up data for fixed effects
xtset actor_code date_code 

* Analysing

local outcomes angernorm fearnorm disgustnorm sadnessnorm joynorm ///
enthusiasmnorm pridenorm hopenorm pos_sentiments_pca neg_sentiments_pca

foreach outcome in `outcomes'{
* Main analyses
* With 95% CI's

xtreg `outcome'_stnd after_state_elec i.month if afd == 0  & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "By date", Model, "Effect of AfD entry", ///
Specification, "Month fixed effects") 

* With 90% CI's
xtreg `outcome'_stnd after_state_elec i.month if afd == 0  & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "By date", Model, "Effect of AfD entry", ///
Specification, "Month fixed effects") 

** Analyses adding calendar month fixed effects
* With 95% CI's

xtreg `outcome'_stnd after_state_elec i.month i.calendar_monthyear_code if afd == 0  & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "By date", Model, "Effect of AfD entry", ///
Specification, "Month and calendar month fixed effects") 

* With 90% CI's
xtreg `outcome'_stnd after_state_elec i.month i.calendar_monthyear_code if afd == 0  & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Without AfD", Period, "By date", Model, "Effect of AfD entry", ///
Specification, "Month and calendar month fixed effects") 

}

*************************************************************************************
** Replicating the analyses without excluding small speeches (less than 100 words) **
*************************************************************************************

* Opening the dataset

use thirdtry_collapsed_monthly_100, clear

* Setting up data for fixed effects

xtset actor_code month 

* Analysing

local outcomes angernorm fearnorm disgustnorm sadnessnorm joynorm ///
enthusiasmnorm pridenorm hopenorm pos_sentiments_pca neg_sentiments_pca

* A fake model just to create a dataset with findings	
	
foreach outcome in `outcomes'{

* Analyses with 95% CI
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Short speeches removed", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses with 90% CI
xtreg `outcome'_stnd after_state_elec i.month if afd == 0 & main_party == 1, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Short speeches removed", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 
}

********************************************************************************
******************* Placebo using elections in other states ********************
********************************************************************************

local outcomes angernorm fearnorm disgustnorm sadnessnorm joynorm ///
enthusiasmnorm pridenorm hopenorm pos_sentiments_pca neg_sentiments_pca

forvalues x = 1/12 {
use collapsed_placebo_`x', clear

xtset actor_code month_placebo_`x'

	foreach outcome in `outcomes'{

	* Analyses with 95% CI
	xtreg `outcome'_stnd placebo_`x' i.month_placebo_`x' if afd == 0 & main_party == 1, ///
	fe cluster(actor_code)
	regsave placebo_`x' using findings.dta, ci level(95) append pval ///
	addlabel (Outcome, `outcome', Sample, "Placebo with other election dates", Period, "Monthly", Model, "placebo_`x'", ///
	Specification, "Year fixed effects") 

	* Analyses with 90% CI
	xtreg `outcome'_stnd placebo_`x' i.month_placebo_`x' if afd == 0 & main_party == 1, ///
	fe cluster(actor_code)
	regsave placebo_`x' using findings_90.dta, ci level(90) append pval ///
	addlabel (Outcome, `outcome', Sample, "Placebo with other election dates", Period, "Monthly", Model, "placebo_`x'", ///
	Specification, "Year fixed effects") 
	}
}

********************************************************************************
**** Placebo using Hessen 2013 election (when AfD did not enter parliament) ****
********************************************************************************

use hessen_collapsed_monthly, clear

* Setting up data for fixed effects

xtset actor_code month 

* Analysing

local outcomes angernorm fearnorm disgustnorm sadnessnorm joynorm ///
enthusiasmnorm pridenorm hopenorm pos_sentiments_pca neg_sentiments_pca

	
foreach outcome in `outcomes'{

* Analyses with 95% CI
xtreg `outcome'_stnd after_state_elec i.month, ///
fe cluster(actor_code)
regsave after_state_elec using findings.dta, ci level(95) append pval ///
addlabel (Outcome, `outcome', Sample, "Placebo Hessen 2013", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 

* Analyses with 90% CI
xtreg `outcome'_stnd after_state_elec i.month, ///
fe cluster(actor_code)
regsave after_state_elec using findings_90.dta, ci level(90) append pval ///
addlabel (Outcome, `outcome', Sample, "Placebo Hessen 2013", Period, "Monthly", Model, "Effect of AfD entry", ///
Specification, "Year fixed effects") 
}


** MANIPULATING DATASET WITH THE FINDINGS OF THE ANALYSES USING MAIN PARTIES ONLY

use findings, clear
rename ci_upper ci_upper_95
rename ci_lower ci_lower_95
save findings_manipulated, replace

use findings_90, clear 
rename ci_upper ci_upper_90
rename ci_lower ci_lower_90

append using findings_manipulated

gen sentiments = 1
replace sentiments = 0 if Outcome == "derogatory_dummy" | Outcome == "dtscore" ///
| Outcome == "dtscorenorm" | Outcome == "dtscore2" | Outcome == "derogatory_dummy2"

replace Sample = "Left-wing MPs" if Sample == "Left-wing parties"
replace Sample = "Right-wing MPs (without AfD)" if Sample == "Right-wing parties (without AfD)"

gen outcome_type = " "
replace outcome_type = "Negative emotions" if Outcome == "angernorm" | Outcome == "fearnorm" ///
| Outcome == "disgustnorm" | Outcome == "sadnessnorm" | Outcome == "neg_sentiments_pca"
replace outcome_type = "Positive emotions"  if Outcome == "joynorm" | Outcome == "enthusiasmnorm" ///
| Outcome == "pridenorm" | Outcome == "hopenorm" | Outcome == "pos_sentiments_pca"

replace outcome_type = "Use of derogatory words and phrases" if Outcome == "dtscore2norm"

gen pca = 0
replace pca = 1 if Outcome == "sentiments_pca" | Outcome == "pos_sentiments_pca" ///
| Outcome == "neg_sentiments_pca"

drop if Outcome == "fake"

replace Sample = "MPs from mainstream parties (excluding Greens)" if Sample == "MPs from mainstream parties (exluding Greens)"
replace Sample = "Agriculture" if Sample == "topic_1"
replace Sample = "Animal" if Sample == "topic_2"
replace Sample = "Broadcast" if Sample == "topic_3"
replace Sample = "Budget" if Sample == "topic_4"
replace Sample = "Data privacy" if Sample == "topic_5"
replace Sample = "EU" if Sample == "topic_6"
replace Sample = "Extremism" if Sample == "topic_7"
replace Sample = "Family" if Sample == "topic_8"
replace Sample = "Federalism" if Sample == "topic_9"
replace Sample = "Gender" if Sample == "topic_10"
replace Sample = "Health" if Sample == "topic_11"
replace Sample = "Investigation" if Sample == "topic_12"
replace Sample = "Labour" if Sample == "topic_13"
replace Sample = "Legislation" if Sample == "topic_14"
replace Sample = "Police" if Sample == "topic_15"
replace Sample = "Procedural" if Sample == "topic_16"
replace Sample = "Refugees" if Sample == "topic_17"
replace Sample = "Research" if Sample == "topic_18"
replace Sample = "Rural" if Sample == "topic_19"
replace Sample = "School" if Sample == "topic_20"
replace Sample = "Transportation" if Sample == "topic_21"
replace Sample = "Volunteering" if Sample == "topic_22"

replace Outcome = "Derogatory language" if Outcome == "dtscore2norm"
replace Outcome = "Emotion score" if Outcome == "sentimentnorm"
replace Outcome = "Emotions (PCA)" if Outcome == "sentiments_pca"
replace Outcome = "Anger" if Outcome == "angernorm"
replace Outcome = "Disgust" if Outcome == "disgustnorm"
replace Outcome = "Fear" if Outcome == "fearnorm"
replace Outcome = "Sadness" if Outcome == "sadnessnorm"
replace Outcome = "Negative emotions (PCA)" if Outcome == "neg_sentiments_pca"
replace Outcome = "Enthusiasm" if Outcome == "enthusiasmnorm"
replace Outcome = "Hope" if Outcome == "hopenorm"
replace Outcome = "Joy" if Outcome == "joynorm"
replace Outcome = "Pride" if Outcome == "pridenorm"
replace Outcome = "Positive emotions (PCA)" if Outcome == "pos_sentiments_pca"

* Dropping derogatory language, because we don't look at it anymore
drop if Outcome == "Derogatory language"

tostring State, replace
replace State = "Excluding Baden-W'berg" if State == "1"
replace State = "Excluding Bavaria" if State == "2"
replace State = "Excluding Berlin" if State == "3"
replace State = "Excluding Brandenburg" if State == "4"
replace State = "Excluding Bremen" if State == "5"
replace State = "Excluding Hamburg" if State == "6"
replace State = "Excluding Hessen" if State == "7"
replace State = "Excluding M'burg-Vorpommer" if State == "8"
replace State = "Excluding N. Rhine-Westphalia" if State == "9"
replace State = "Excluding Niedersachsen" if State == "10"
replace State = "Excluding Rhineland-Palatinate" if State == "11"
replace State = "Excluding Saarland" if State == "12"
replace State = "Excluding Saxony" if State == "13"
replace State = "Excluding Sax-Anhalt" if State == "14"
replace State = "Excluding Schleswig-Holstein" if State == "15"
replace State = "Excluding Thuringia" if State == "16"

*replace Months = 9999 if Months == .
gen Months = 9999 

* Fix models in the spillover placebo models
replace Model = "13 Mar 2016" if Model == "placebo_1"
replace Model = "14 Oct 2018" if Model == "placebo_2"
replace Model = "18 Sep 2016" if Model == "placebo_3"
replace Model = "14 Sep 2014" if Model == "placebo_4"
replace Model = "10 May 2015" if Model == "placebo_5"
replace Model = "15 Feb 2015" if Model == "placebo_6"
replace Model = "28 Oct 2018" if Model == "placebo_7"
replace Model = "04 Sep 2016" if Model == "placebo_8"
replace Model = "15 Oct 2015" if Model == "placebo_9"
replace Model = "14 May 2017" if Model == "placebo_10"
replace Model = "31 Aug 2014" if Model == "placebo_11"
replace Model = "07 May 2017" if Model == "placebo_12"

saveold findings_m, replace version (12)

